﻿<%@ Page Title="Edit Pathway" Language="C#" MasterPageFile="/Administration/Site.Master" AutoEventWireup="true" CodeBehind="EditPathways.aspx.cs" Inherits="AdministrationWeb.Administration.EditPathways" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="headerText" runat="server">
    Edit Pathway
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    Select Focus Area
    <asp:DropDownList ID="ddlFocusArea" runat="server" AutoPostBack="True" 
        DataSourceID="sqlFocus" DataTextField="focus_name" 
        DataValueField="focus_id" Height="16px" Width="300px">
    </asp:DropDownList>
    <asp:SqlDataSource ID="sqlFocus" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ApplicationConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:ApplicationConnectionString.ProviderName %>" 
        SelectCommand="SELECT focus_id, focus_name  FROM lkup_focus_area ORDER BY focus_name" >
    </asp:SqlDataSource>
    <br />
    <br />
    <br />
    <asp:SqlDataSource ID="SqlPathway" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ApplicationConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:ApplicationConnectionString.ProviderName %>"         
        OldValuesParameterFormatString="original_{0}"
        SelectCommand="SELECT pathway_id, pathway_name, (SELECT COUNT(*) FROM mentor m WHERE m.pathway_id = p.pathway_id) AS 'num_mentors' FROM lkup_pathway p WHERE focus_id = ?focus_id ORDER BY pathway_name" 
        ConflictDetection="CompareAllValues" DeleteCommand="DELETE FROM lkup_pathway
WHERE pathway_id = ?original_pathway_id
AND pathway_name = ?original_pathway_name" InsertCommand="INSERT INTO lkup_pathway (pathway_name, focus_id)
VALUES(?pathway_name, ?focus_id)" UpdateCommand="UPDATE lkup_pathway
SET pathway_name = ?pathway_name
WHERE pathway_id = ?original_pathway_id
AND pathway_name = ?original_pathway_name">
        <DeleteParameters>
            <asp:Parameter Name="original_pathway_id" />
            <asp:Parameter Name="original_pathway_name" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="pathway_name" />
            <asp:Parameter Name="focus_id" />
        </InsertParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="ddlFocusArea" Name="focus_id" 
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="pathway_name" />
            <asp:Parameter Name="original_pathway_id" />
            <asp:Parameter Name="original_pathway_name" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:GridView ID="gdvPathway" runat="server" DataSourceID="SqlPathway" 
        AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" 
        ondatabound="gdvPathway_DataBound" BorderColor="#006600" 
        BorderStyle="Double" CellPadding="4" ForeColor="#333333" onrowupdated="gdvPathway_RowUpdated" 
        onrowdeleted="gdvPathway_RowDeleted" CellSpacing="4" DataKeyNames="pathway_id">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:BoundField DataField="pathway_id" HeaderText="Id" 
                ReadOnly="True" DataFormatString="{0:d}" Visible="False" >
            <ItemStyle HorizontalAlign="Center" Width="100px" />
            </asp:BoundField>
            <asp:TemplateField AccessibleHeaderText="Name" HeaderText="Name">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("pathway_name") %>'></asp:TextBox>
                    <br />
                    <asp:RequiredFieldValidator ID="rfvName" runat="server" 
                                                ControlToValidate="TextBox1" ErrorMessage="*Name can not be empty" 
                                                ForeColor="Red" ValidationGroup="1" />
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("pathway_name") %>' />
                </ItemTemplate>
                <ItemStyle Width="735" />
            </asp:TemplateField>
            <asp:BoundField DataField="num_mentors" 
                HeaderText="Mentors" ReadOnly="True" >
            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="120" />
            </asp:BoundField>
            <asp:CommandField ButtonType="Button" ShowEditButton="True" 
                ValidationGroup="1" >            
            <ControlStyle CssClass="button" Width="90" />
            <ItemStyle HorizontalAlign="Center" Width="96" />
            </asp:CommandField>
            <asp:ButtonField ButtonType="Button" CommandName="Delete" Text="Delete" >            
            <ControlStyle CssClass="button" Width="90" />
            <ItemStyle HorizontalAlign="Center" Width="96" />
            </asp:ButtonField>
        </Columns>
        <EditRowStyle BackColor="#7C6F57" />
        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#E3EAEB" />
        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F8FAFA" />
        <SortedAscendingHeaderStyle BackColor="#246B61" />
        <SortedDescendingCellStyle BackColor="#D4DFE1" />
        <SortedDescendingHeaderStyle BackColor="#15524A" />
    </asp:GridView>
    <br />
    <hr />
    <br />
    <strong>Creat New Pathway</strong><br />
    <br />
    Pathway Name:&nbsp; 
    <asp:TextBox ID="txtNewName" runat="server" Width="400px" ValidationGroup="2" /><br/>
    <asp:RequiredFieldValidator ID="rfvPathway" runat="server" 
        ErrorMessage="*Must enter a pathway name" ForeColor="Red" 
        ControlToValidate="txtNewNAme" ValidationGroup="2">*Must enter a pathway name</asp:RequiredFieldValidator>
    <br />
    <br />
    <asp:Button ID="btnInsert" runat="server" Text="Create New Pathway" 
        onclick="btnInsert_Click" ValidationGroup="2" CssClass="button" />
    <br />
    <br />
    <asp:Label ID="lblMessage" runat="server" Font-Italic="True" 
        Font-Size="Smaller" ViewStateMode="Enabled"></asp:Label>
    <br />
    </asp:Content>
